
#ifndef _SINGLETON_H_
#define _SINGLETON_H_
#pragma once

#ifdef _DEBUG
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
	#include <crtdbg.h>
	#define NEW_MEM_LEAK (_NORMAL_BLOCK, __FILE__,__LINE__)
#else
	#define NEW_MEM_LEAK 
#endif

template <class T>
/*
Singleton class
Creates a unique instance of a type T
*/
class TSingleton
{
protected:
	static T *m_pInstance;
	

public:
	virtual ~TSingleton()
	{
	}

	//static int m_counts;
	
	/*
	Get()
	Returns the instance or if none is created yet creates one
	*/
	inline static T* Get()
	{
		if (!m_pInstance)
		{
			//_CrtCheckMemory();
			m_pInstance = new NEW_MEM_LEAK T();
		}
		return (m_pInstance);
	}

	/*
	Del()
	Frees memory and resets the pointer
	*/
	static void Del()
	{
		if(m_pInstance)
		{
			delete (m_pInstance);
			m_pInstance = NULL;
		}
	}

};

template <class T>
T* TSingleton<T>::m_pInstance = 0;


#endif